home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1551 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  61 lines

  1. Newsgroups: comp.lang.c
  2. Path: info.physics.utoronto.ca!olivers
  3. From: olivers@helios.physics.utoronto.ca (Oliver Schonborn)
  4. Subject: Help:  crash when doing fprintf
  5. Message-ID: <DL74rA.L5v@info.physics.utoronto.ca>
  6. Nntp-Posting-Host: helios.physics.utoronto.ca
  7. Sender: news@info.physics.utoronto.ca (System Administrator)
  8. Organization: University of Toronto - Dept. of Physics
  9. Date: Mon, 15 Jan 1996 00:16:22 GMT
  10.  
  11.  
  12. Hello folks!
  13.  
  14. My program crashes when it executes the following statements:
  15.  
  16.         char frootn[200]=".",
  17.          fout[200]  ="";
  18.         float time;
  19.         FILE *fp;
  20.         ....
  21.     sprintf(fout,"%s/test%-.5g",frootn,time);
  22.     printf("Outputting to %s...\n",fout);
  23.     fp=fopen(fout,"w");
  24.     fprintf(fp,"Hello\n");
  25.  
  26. This is what fp points to at crash time:
  27.  
  28. 0x40001038  struct FILE {
  29.     __cnt = 0;
  30.     __ptr =   00000000;
  31.     __base =   00000000;
  32.     __flag = 2;
  33.     __fileL = 3;
  34.     __fileH = 0;
  35. }
  36.  
  37. It crashes deep inside the fprintf.  A trace with the debugger
  38. indicates where (main called _fprintf which called _wrtchk which
  39. called _findbuf which called malloc):
  40.  
  41.  0 malloc@libc + 0x00000470 (0x7b012538, 0x7b011168, 0x7b011164, 0x7b011160)
  42.  1 _findbuf@libc + 0x000000fc (0x160, 0x8, 0x160, 0x7b0335b0)
  43.  2 _wrtchk@libc + 0x00000058 (0x40061f40, 0x40061d38, 0x40061938, 0x3f7b53d2)
  44.  3 _fprintf@libc + 0x00000024 (0x3c23d71a, 0x7b0336e4, 0x7b014e60, 0x7b014e6c)
  45.  4 main (argc = 3, argv = 0x7b033494)    [sfbynorm.c: 556]
  46.  
  47. I've never seen anything like that bug before.  I used gcc 2.7.1
  48. with -Wall -pedantic and get no warnings whatsoever.  With lint the
  49. only warning I get is a possible pointer alignment problem from the
  50. 2 lines which define (and initialize) frootn[] and fout[], though I
  51. don't know whether I should take that seriously.
  52.  
  53. Anybody have any clue?  Thanks for any help,
  54.  
  55. Oliver
  56. -- 
  57.   _________________________________........----------------,
  58.  /\  OliverS@physics.utoronto.ca                            \
  59.  \_|  Condensed-Matter/Quantum-Optics Theory Group           )
  60.    /  Physics Dept University of Toronto -- Canada          /
  61.